<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="form-container">
  <div fxLayout="row" fxLayoutAlign="start center">
    <h1>{{formName}}</h1>
    <button mat-icon-button (click)="openDialog()"><mat-icon>info_outline</mat-icon></button>
  </div>
  <div class="gv-form-section">
    <div fxLayout="column">
        <mat-slide-toggle matTooltip="{{isEnabled() ? 'Disable custom form ?' : 'Enable custom form ?'}}"
                          [matTooltipPosition]="'after'"
                          (change)="enableForm($event)"
                          [checked]="isEnabled()" [disabled]="!canEdit()">
          Enable custom {{template}} form.
        </mat-slide-toggle>
        <mat-hint style="font-size: 75%;">Override the default {{template}} page to fit your company requirements.</mat-hint>
    </div>
  </div>

  <div class="gv-form-section">
    <mat-tab-group (selectedTabChange)="onTabSelectedChanged($event);">
      <mat-tab label="Html" [disabled]="!isEnabled() || !canEdit()">
        <div style="position:relative;">
          <codemirror #editor [(ngModel)]="formContent" [config]="config" (change)="onContentChanges($event)"></codemirror>
        </div>
      </mat-tab>
      <mat-tab label="Preview" [disabled]="!isEnabled() || !canEdit()">
        <iframe frameborder="0" class="preview" #preview width="100%" (load)="resizeIframe()">
        </iframe>
      </mat-tab>
    </mat-tab-group>
  </div>

  <div>
    <button *ngIf="canEdit()" mat-raised-button color="primary" [disabled]="!formChanged" (click)="save()">SAVE</button>
  </div>

  <div *ngIf="formFound && deleteMode" class="form-delete-zone" fxLayout="column">
    <p>This operation cannot be undone.</p>
    Form template will be deleted, it will no longer be use to override default {{formName}} template.
    <div class="form-delete-button" fxLayout="row">
      <span fxFlex></span>
      <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
    </div>
  </div>
</div>
